<?php
/**
 * Created by PhpStorm.
 * User: xh
 * Date: 2019/11/22
 * Time: 3:52 PM
 */

namespace weChat;


class Pit
{
    /** 微信 appId
     * @var string
     */
    public static $AppId = '';

    /** 微信 AppSecret
     * @var string
     */
    public static $AppSecret = '';

    /** 发送请求
     * @param $url
     * @param array $data
     * @return bool|mixed
     */
    protected static function Curl($url,$data=array()){
        $headers = array(
            'Accept:application/json;',
            'Content-Type:application/json; charset=UTF-8',
        );
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        if(1 == strpos("$".$url, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        if(!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        //防止抱死 30秒解除
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        $result = curl_exec($curl);
        $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
        if($httpCode == 200){
            return $result;
        }else{
            return false;
        }
    }
}